﻿using System;
using System.Collections.Generic;
using System.Text;
using EM.OA.DataModel.DBModel;
using EM.FrameWork;
using EM.OA.Common;
using EM.OA.DataTransferObject;

namespace EM.OA.BLL
{
    public class RemindBLL : BLLBase<EMOA_Remind>
    {


        public RemindDTO GetRemindByObjectID(Guid objectID)
        {
            RemindDTO dto = new RemindDTO();
            List<EMOA_Remind> list = GetList(p => p.ObjectID == objectID);
            if (list.Count > 0)
            {
                foreach (EMOA_Remind item in list)
                {
                    dto.RemindMethod += EnumHelper.GetEnumDescription<GlobalEnum.RemindKind>(item.RemindMethod.Value) + ",";

                }
                dto.RemindMethod = dto.RemindMethod.TrimEnd(',');
                dto.RemindType = EnumHelper.GetEnumDescription<GlobalEnum.RemindTimeKind>(list[0].RemindType.Value);
                dto.RepeatTime = list[0].RepeatTime;
                dto.RemindTime = list[0].RemindTime;
                dto.StartDate = list[0].BeginTime;
                dto.EndDate = list[0].EndTime;
                if (list[0].RemindType == (int)GlobalEnum.RemindTimeKind.Now)
                    dto.Detail = EnumHelper.GetEnumDescription<GlobalEnum.RemindTimeKind>(list[0].RemindType.Value);
                else if (list[0].RemindType == (int)GlobalEnum.RemindTimeKind.Once)
                    dto.Detail = list[0].RemindTime.Value.ToString("yyyy-MM-dd HH:mm");
                else if (list[0].RemindType == (int)GlobalEnum.RemindTimeKind.Day)
                    dto.Detail = string.Format("{0}{1}", dto.RemindType, list[0].RemindTime.Value.ToString("HH:mm"));
                else if (list[0].RemindType == (int)GlobalEnum.RemindTimeKind.Month)
                    dto.Detail = string.Format("{0}{1}日 {2}", dto.RemindType, list[0].RepeatTime, list[0].RemindTime.Value.ToString("HH:mm"));
                else if (list[0].RemindType == (int)GlobalEnum.RemindTimeKind.Week)
                    dto.Detail = string.Format("{0}{1} {2}", dto.RemindType, list[0].RepeatTime.TrimEnd(','), list[0].RemindTime.Value.ToString("HH:mm"));
                else if (list[0].RemindType == (int)GlobalEnum.RemindTimeKind.Year)
                    dto.Detail = string.Format("{0}{1}日 {2}", dto.RemindType, list[0].RepeatTime.Replace('-','月'), list[0].RemindTime.Value.ToString("HH:mm"));
                if (list[0].BeginTime.HasValue)
                    dto.Detail += " 开始于" + list[0].BeginTime.Value.ToString("yyyy-MM-dd");
                if (list[0].EndTime.HasValue)
                    dto.Detail += " 结束于" + list[0].EndTime.Value.ToString("yyyy-MM-dd");
            }
            return dto;
        }
    }


}